/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.agtranscontinental.sisref.model;

import com.agtranscontinental.sisref.dto.SerieDto;
import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 *
 * @author ericson
 */
@Entity
@Table(name = "serie")
@NamedQueries({
    @NamedQuery(name = "Serie.findAll", query = "SELECT s FROM Serie s"),
    @NamedQuery(name = "Serie.findByOrden", query = "SELECT s FROM Serie s WHERE s.orden.id = :id")
})
public class Serie implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "id")
    private Integer id;
    @Size(max = 20)
    @Column(name = "srie")
    private String srie;
    @Size(max = 60)
    @Column(name = "tre_sze")
    private String treSze;
    @Size(max = 150)
    @Column(name = "ply_star_rting")
    private String plyStarRting;
    @Size(max = 150)
    @Column(name = "pttern")
    private String pttern;
    @Size(max = 150)
    @Column(name = "spec")
    private String spec;
    @Size(max = 150)
    @Column(name = "cstmer")
    private String cstmer;
    @JoinColumn(name = "id_oden", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Orden orden;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "serie")
    private List<Revision> revisionList;

    public Serie() {
    }

    public Serie(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getSrie() {
        return srie;
    }

    public void setSrie(String srie) {
        this.srie = srie;
    }

    public String getTreSze() {
        return treSze;
    }

    public void setTreSze(String treSze) {
        this.treSze = treSze;
    }

    public String getPlyStarRting() {
        return plyStarRting;
    }

    public void setPlyStarRting(String plyStarRting) {
        this.plyStarRting = plyStarRting;
    }

    public String getPttern() {
        return pttern;
    }

    public void setPttern(String pttern) {
        this.pttern = pttern;
    }

    public String getSpec() {
        return spec;
    }

    public void setSpec(String spec) {
        this.spec = spec;
    }

    public Orden getOrden() {
        return orden;
    }

    public void setOrden(Orden orden) {
        this.orden = orden;
    }

    public List<Revision> getRevisionList() {
        return revisionList;
    }

    public void setRevisionList(List<Revision> revisionList) {
        this.revisionList = revisionList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Serie)) {
            return false;
        }
        Serie other = (Serie) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.agtranconstinental.sisref.Serie[ id=" + id + " ]";
    }

    public SerieDto toSerieDto() {
        SerieDto s = new SerieDto();
        s.setId(id);
        s.setIdOden(orden.getId());
        s.setPlyStar(plyStarRting);
        s.setPttern(pttern);
        s.setSpec(spec);
        s.setSrie(srie);
        s.setTreSze(treSze);
        s.setCstmer(cstmer);
        return s;
    }

    /**
     * @return the cstmer
     */
    public String getCstmer() {
        return cstmer;
    }

    /**
     * @param cstmer the cstmer to set
     */
    public void setCstmer(String cstmer) {
        this.cstmer = cstmer;
    }
}
